package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class operationDelet implements Ioperation{
    public void work(BookList bookList) {
        System.out.println("删除图书！");
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();
        int pos = -1;
        int currentusesize = bookList.getUsesize();
        int i = 0;
        for ( ;i < currentusesize; i++) {
            Book book = bookList.getbook(i);
            if(book.getName().equals(name)) {
                   pos = i;
                   break;
            }

        }
        if(i>=currentusesize){
            System.out.println("没有你要找的图书");
            return ;
        }
        for (int j = 0; j < currentusesize-1; j++) {
            Book book = bookList.getbook(j+1);
            bookList.setBooks(j,book);
        }
        bookList.setUsesize(currentusesize-1);
        bookList.setBooks(currentusesize,null);

        System.out.println("删除成功！");



    }
}
